package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MeetingRoomApplication;
import com.ruoyi.system.service.IMeetingRoomApplicationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.Employee;

/**
 * 会议室申请记录Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@Controller
@RequestMapping("/system/application")
public class MeetingRoomApplicationController extends BaseController
{
    private String prefix = "system/application";

    @Autowired
    private IMeetingRoomApplicationService meetingRoomApplicationService;

    @RequiresPermissions("system:application:view")
    @GetMapping()
    public String application()
    {
        return prefix + "/application";
    }

    /**
     * 查询会议室申请记录列表
     */
    @RequiresPermissions("system:application:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MeetingRoomApplication meetingRoomApplication)
    {
        startPage();
        List<MeetingRoomApplication> list = meetingRoomApplicationService.selectMeetingRoomApplicationList(meetingRoomApplication);
        return getDataTable(list);
    }

    /**
     * 导出会议室申请记录列表
     */
    @RequiresPermissions("system:application:export")
    @Log(title = "会议室申请记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MeetingRoomApplication meetingRoomApplication)
    {
        List<MeetingRoomApplication> list = meetingRoomApplicationService.selectMeetingRoomApplicationList(meetingRoomApplication);
        ExcelUtil<MeetingRoomApplication> util = new ExcelUtil<MeetingRoomApplication>(MeetingRoomApplication.class);
        return util.exportExcel(list, "会议室申请记录数据");
    }

    /**
     * 根据部长id查询部门下的所有员工
     */
    @RequiresPermissions("system:application:list222")
    @PostMapping("/selectEmployees")
    @ResponseBody
    public AjaxResult selectEmployeesByMinisterId(Long ministerId)
    {
        List<Employee> list = meetingRoomApplicationService.selectEmployeesByMinisterId(ministerId);
        return AjaxResult.success(list);
    }

    /**
     * 新增会议室申请记录
     */
    @RequiresPermissions("system:application:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会议室申请记录
     */
    @RequiresPermissions("system:application:add")
    @Log(title = "会议室申请记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MeetingRoomApplication meetingRoomApplication)
    {
        return toAjax(meetingRoomApplicationService.insertMeetingRoomApplication(meetingRoomApplication));
    }

    /**
     * 修改会议室申请记录
     */
    @RequiresPermissions("system:application:edit")
    @GetMapping("/edit/{applicationId}")
    public String edit(@PathVariable("applicationId") Long applicationId, ModelMap mmap)
    {
        MeetingRoomApplication meetingRoomApplication = meetingRoomApplicationService.selectMeetingRoomApplicationByApplicationId(applicationId);
        mmap.put("meetingRoomApplication", meetingRoomApplication);
        return prefix + "/edit";
    }

    /**
     * 修改保存会议室申请记录
     */
    @RequiresPermissions("system:application:edit")
    @Log(title = "会议室申请记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MeetingRoomApplication meetingRoomApplication)
    {
        return toAjax(meetingRoomApplicationService.updateMeetingRoomApplication(meetingRoomApplication));
    }

    /**
     * 删除会议室申请记录
     */
    @RequiresPermissions("system:application:remove")
    @Log(title = "会议室申请记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(meetingRoomApplicationService.deleteMeetingRoomApplicationByApplicationIds(ids));
    }
}
